import 'package:casdon/common/utils/string_externtion.dart';
import 'package:casdon/modules/recipe/data/api/recipe_favorite_list_api.dart';
import 'package:casdon/modules/recipe/data/model/recipe_placeholder_data.dart';
import 'package:casdon/modules/recipe/ui/widgets/Recipe_card_item.dart';

class RecipeFavoriteModel extends RecipeCardData {
  @override
  int get sort => 0;
  final String id;
  final String name;
  final String mainImg;
  final String view;
  final String likes;
  final String collection;
  final bool isControl;
  @override
  final bool isVideo;

  RecipeFavoriteModel({
    required this.id,
    required this.name,
    required this.mainImg,
    required this.view,
    required this.likes,
    required this.collection,
    required this.isControl,
    required this.isVideo,
  });

  @override
  bool get isSmart => isControl;
  @override
  String? get url => null;
  @override
  String get recipeId => id;

  @override
  String get imgUrl => mainImg.cropParams700;

  @override
  RecipeCardData placeholder() {
    throw UnimplementedError();
  }

  @override
  String get count => "0";
  @override
  String get title => name;

  @override
  String get viewCount => view;

  // 静态方法转换
  static RecipeFavoriteModel fromApi(RecipeFavorite response) {
    return RecipeFavoriteModel(
      id: response.id,
      name: response.name,
      mainImg: (response.mainImg ?? "").isEmpty
          ? recipePlaceHolderImgUrl
          : (response.mainImg ?? "").split(",").first,
      view: response.view ?? "0",
      likes: response.likes ?? "0",
      collection: response.collection ?? "0",
      isControl: (response.isControl ?? 0) == 1 ? true : false,
      isVideo: (response.videoCoverUrls ?? "").isNotEmpty,
    );
  }

  // 批量转换的静态方法
  static List<RecipeFavoriteModel> listFromApi(List<RecipeFavorite> items) {
    return items.map(fromApi).toList();
  }
}
